package com.tinyseed.emcp.api.basicdata.rest;

import com.tinyseed.emcp.api.basicdata.model.MonitorRelationInputDTO;
import com.tinyseed.emcp.api.basicdata.model.OrganizeInputDTO;
import com.tinyseed.emcp.api.basicdata.service.OrganizeService;
import com.tinyseed.hmxx.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/organize")
public class OrganizeController extends BaseController {

    private final OrganizeService organizeService;

    public OrganizeController(OrganizeService organizeService) {
        this.organizeService = organizeService;
    }

    @GetMapping(value = "/optionList")
    @ResponseBody
    public ResponseEntity optionList() {
        return new ResponseEntity<>(organizeService.getOptionList(), HttpStatus.OK);

    }

    @GetMapping(value = "/list")
    @ResponseBody
    public ResponseEntity list() {
        return new ResponseEntity<>(organizeService.getList(), HttpStatus.OK);

    }

    @PostMapping(value = "/getDataById")
    @ResponseBody
    public ResponseEntity getDataById(Long id) {
        return new ResponseEntity<>(organizeService.getDataById(id), HttpStatus.OK);

    }

    @GetMapping(value = "/getDeptByOrganize")
    @ResponseBody
    public ResponseEntity getDeptByOrganize(Long id) {
        return new ResponseEntity<>(organizeService.getDataById(id), HttpStatus.OK);
    }


    @PostMapping(value = "/saveDept")
    @ResponseBody
    public ResponseEntity saveDept(Long id, @RequestParam(value = "dept[]")List<Long> dept) {
        organizeService.addDept(id,dept);
        return new ResponseEntity<>(HttpStatus.OK);
    }



    @PostMapping(value = "/save")
    @ResponseBody
    public ResponseEntity save(@RequestBody OrganizeInputDTO organizeInputDTO) {
        organizeService.save(organizeInputDTO);
        return new ResponseEntity<>("操作成功",HttpStatus.OK);
    }

    @PostMapping(value = "/deleteById")
    @ResponseBody
    public ResponseEntity deleteById(Long id) {
        return new ResponseEntity<>(organizeService.deleteById(id), HttpStatus.OK);

    }
}
